import { getDetails } from '@/services/sales/sweep';

export default {
  namespace: 'sweepstakes',
  state: {
    visible: false,
    editVisible: false,
    editData: {},
    /** add新增 / edit编辑 / view查看  */
    type: '',
    relaod: false,
    selectedRowKeys: [],
    selectedRows: [],
  },
  reducers: {
    update: (state, { payload }) => ({
      ...state,
      ...payload,
    }),
  },
  effects: {
    *getDetails({ payload }, { call, put }) {
      const { code, data } = yield call(getDetails, payload);
      if (code === 200 && data) {
        let obj = { ...data };
        if (data?.startTime && data?.endTime) {
          obj.activityTimeRange = [data?.startTime, data?.endTime];
        }
        // if (data?.useTimeType === 1 && useBeginDate && useEndTime) {
        //   obj.useTimeRange = [dayjs(useBeginDate), dayjs(useEndTime)];
        // }
        // if (data?.useTimeType === 2 && effectiveDuration) {
        //   obj.useTimeRange = effectiveDuration;
        // }
        // obj.minandsale = {
        //   first: minimumConsumption,
        //   second: price,
        // };
        yield put({
          type: 'update',
          payload: {
            editData: obj,
            visible: true,
          },
        });
      }
    },
  },
};
